package interview;

import java.util.*;

public class lc2170 {
    public static void main(String[] args) {
        System.out.println(minimumOperations(new int[]{3,1,3,2,4,3}));
    }
    public static int minimumOperations(int[] nums) {
        int n = nums.length;
        int ans = 0;
        Map<Integer, Integer> map1 = new HashMap<>();
        Map<Integer, Integer> map2 = new HashMap<>();
        for (int i = 0; i < n; i += 2) {
            if(map1.containsKey(nums[i])){
                map1.put(nums[i], map1.get(nums[i]) + 1);
            }
            else
                map1.put(nums[i], 1);
        }
        for (int i = 1; i < n; i += 2) {
            if(map2.containsKey(nums[i])){
                map2.put(nums[i], map2.get(nums[i]) + 1);
            }
            else
                map2.put(nums[i], 1);
        }
        //分别表示偶数与奇数的众数与次众数以及出现的次数
        int[][] a, b;
        a = findNum(map1);
        b = findNum(map2);
        if(a[0][0] == b[0][0])
            ans = n - Math.max(a[1][1] + b[0][1], a[0][1] + b[1][1]);
        else
            ans = n - a[0][1] - b[0][1];
        return ans;
    }
    public  static int[][] findNum(Map<Integer, Integer> map){
        int[][] a = new int[2][2];
        //众数以及出现次数
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if(entry.getValue() > a[0][1]){
                a[0][0] = entry.getKey();
                a[0][1] = entry.getValue();
            }
        }
        //次众数以及出现次数
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if(entry.getValue() > a[1][1] && entry.getKey() != a[0][0]){
                a[1][0] = entry.getKey();
                a[1][1] = entry.getValue();
            }
        }
        return a;
    }
}
